/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servergui;

import Shared.NodeInfo;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author Backkom
 */
public class TreeRenderer extends DefaultTreeCellRenderer {

    ImageIcon imgDB;
    ImageIcon imgTB;
    ImageIcon imgRoot;

    public TreeRenderer() {
        imgDB = new ImageIcon("src/database_icon.png");
        imgTB = new ImageIcon("src/table_icon.png");
        imgRoot = new ImageIcon("src/root_icon.png");
    }

    @Override
    public Component getTreeCellRendererComponent(
            JTree tree,
            Object value,
            boolean sel,
            boolean expanded,
            boolean leaf,
            int row,
            boolean hasFocus) {

        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        String type = ((NodeInfo) node.getUserObject()).GetType();
        if (type.compareToIgnoreCase("root") == 0) {
            setIcon(imgRoot);
        }
        if (type.compareToIgnoreCase("db") == 0) {
            setIcon(imgDB);
        }
        if (type.compareToIgnoreCase("tb") == 0) {
            setIcon(imgTB);
        }        
        if(sel)
            setForeground(Color.WHITE);                    
        else
            setForeground(Color.BLUE);                    
        return this;
    }
}
